package com.heying.springcore.aop.transaction;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

@Component

public class UserDao {

    @Value("#{transaction.tl}")
    private ThreadLocal<Connection> tl;

    public UserDao() {


    }

    public void insertOne(UserInfo user) throws SQLException {
        String insert = "insert into userinfo values(?,?)";
        PreparedStatement pstmt = tl.get().prepareStatement(insert);
        pstmt.setInt(1, user.getId());
        pstmt.setString(2, user.getName());
        pstmt.executeUpdate();

    }
}
